package laravel;

import javafx.collections.FXCollections;
import javafx.collections.ObservableList;
import laravel.mvc.view.route.Group;
import laravel.mvc.view.route.Route;
import php.PhpFile;

import static laravel.mvc.view.route.Route.Method.GET;
import static laravel.mvc.view.route.Route.Method.POST;

/**
 * Created by nuno-rafael-figueiredo on 04-05-2014.
 */
public class Routes extends PhpFile{
    private transient final ObservableList<Group> groups = FXCollections.observableArrayList();
    private transient final ObservableList<Route> routes = FXCollections.observableArrayList();

    public Routes() {
        super(Laravel.APP_FOLDER, "routes");

        createRoute(
                GET,
                "/",
                "home",
                "HomeController@home"
        );

        final Group csrf = createGroup("csrf");
        csrf.createRoute(POST, "/account/create", "account-create-post", "AccountController@postCreate");
        csrf.createRoute(POST, "/account/sign-in", "account-sign-in-post", "AccountController@postSignIn");


        final Group guest = createGroup("guest");
        guest.createRoute(GET, "/account/sign-in", "account-sign-in", "AccountController@getSignIn");
        guest.createRoute(GET, "/account/create", "account-create", "AccountController@getCreate");
        guest.createRoute(GET, "/account/activate/{code}", "account-activate", "AccountController@getActivate");
    }

    public Route createRoute(Route.Method method, String path, String as, String uses) {
        Route route = new Route(method, path, as, uses);
        add(route);
        routes.add(route);
        return route;
    }

    public Group createGroup(String name) {
        Group group = new Group(name);
        groups.add(group);
        add(group);
        return group;
    }

    public ObservableList<Group> getGroups() {
        return groups;
    }

    public ObservableList<Route> getRoutes() {
        return routes;
    }
}
